package br.ucb.musicbay.musica;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import br.ucb.musicbay.album.Album;

@Entity
@Table(name = "musica")
public class Musica implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer idMusica;
	private Album album;
	private String nome;
	private Float duracao;
	private Integer faixa;
	
	
	@Column(name = "faixa")
	public Integer getFaixa() {
		return faixa;
	}
	public void setFaixa(Integer faixa) {
		this.faixa = faixa;
	}
	
	@Id
	@GeneratedValue
	@Column(name = "id_musica")
	public Integer getIdMusica() {
		return idMusica;
	}
	public void setIdMusica(Integer idMusica) {
		this.idMusica = idMusica;
	}
	
	@ManyToOne
	@OnDelete(action = OnDeleteAction.CASCADE)
	@JoinColumn(name = "id_album")
	public Album getAlbum() {
		return album;
	}
	public void setAlbum(Album idAlbum) {
		this.album = idAlbum;
	}
	
	public String getNome() {
		return nome;
	}
	public void setNome(String nome) {
		this.nome = nome;
	}
	
	@Column(name = "duracao")
	public Float getDuracao() {
		return duracao;
	}
	public void setDuracao(Float duracao) {
		this.duracao = duracao;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((album == null) ? 0 : album.hashCode());
		result = prime * result
				+ ((idMusica == null) ? 0 : idMusica.hashCode());
		result = prime * result + ((nome == null) ? 0 : nome.hashCode());
		result = prime * result + ((duracao == null) ? 0 : duracao.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Musica other = (Musica) obj;
		if (album == null) {
			if (other.album != null)
				return false;
		} else if (!album.equals(other.album))
			return false;
		if (idMusica == null) {
			if (other.idMusica != null)
				return false;
		} else if (!idMusica.equals(other.idMusica))
			return false;
		if (nome == null) {
			if (other.nome != null)
				return false;
		} else if (!nome.equals(other.nome))
			return false;
		if (duracao == null) {
			if (other.duracao != null)
				return false;
		} else if (!duracao.equals(other.duracao))
			return false;
		return true;
	}
	@Override
	public String toString() {
		return "Musica [idMusica=" + idMusica + ",\n album=" + album + ",\n nome="
				+ nome + ",\n preco=" + duracao + "]";
	}
	
	
}
